<div class="switch-board-round">
    <ul class="clearfix">
      	<li>
      		<a href="#" class="tip-top" data-original-title="Add New">
      			<span class="srabon-sprite plus_sl"></span>
      		</a>
      	</li>

      	<li>
      		<a href="#" class="tip-top" data-original-title="Delete">
      			<span class="srabon-sprite busy_sl"></span>
      		</a>
      	</li>
    </ul>
</div>
<?php echo $this->partial($this->includeDir . '/submenu.php', array('main_title' => 'Users Manager', 'sub_title' => 'List user'));?>
<div class="row-fluid">
	<div class="span12">
		<table id="tbl-data" class="table table-striped table-bordered table-hover">
			<thead>
				<tr>
					<th class="center"><label><input type="checkbox" /><span class="lbl"></span> </label></th>
					<th class="center">ID</th>
					<th class="center">Email</th>
					<th class="center">Full name</th>
					<th class="center">Status</th>
					<th class="center">Birthday</th>
					<th class="hidden-480 center">Group</th>
					<th class="hidden-phone center">Created</th>
					<th class="hidden-480 center">Status</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<?php
	$linkLoadData = $this->cmsUrl(array(
									'module' => 'admin',
									'controller' => 'admin-user',
									'action' => 'load-data-table'
									));
	$linkDelete = $this->cmsUrl(array(
									'module' => 'admin',
									'controller' => 'admin-user',
									'action' => 'delete'
									));	
	$linkStatus = $this->cmsUrl(array(
									'module' => 'admin',
									'controller' => 'admin-user',
									'action' => 'scandir(directory)tatus'
									));																
?>

<script type="text/javascript" language="javascript" class="init">
	$(function() {
		var table = $('#tbl-data').DataTable({
			"bAutoWidth": false,
			"bProcessing" 	: true,
			"bServerSide" 	: true,
			"sAjaxSource" 	: '<?php echo $linkLoadData?>',
			'columns':[
                {"bSortable": false, 'data':'ckb', 'class' : 'center'},	
                {'data':'id', 'class' : 'center'},					
                {'data':'email'},
                {'data':'fullname'},
                {'data':'status', 'class' : 'center'},
                {'data':'birthday', 'class' : 'center'},
                {'data':'group_name'},
                {'data':'created', 'class' : 'hidden-phone center'},
                { "bSortable": false, 'data' : 'control', 'class' : 'center'},
            ],
            "aaSorting": [[ 1, "desc" ]]
		});
		
		$('#tbl-data').on('click', '#table-delete-btn', function () {
			var id = $(this).parents('tr').attr('id');
			bootbox.confirm("Are you sure to delete this item?", function(result) {
				if(result){
					$.post('<?php echo $linkDelete?>', {id : id}, function(){
						table.draw(false);
					})
				}
			})
			return false;
		});	
			
		$('#tbl-data').on('click', '#tbl-delete-btn', function () {
			var id = $(this).parents('tr').attr('id');
			bootbox.confirm("Are you sure to delete this item?", function(result) {
				if(result){
					$.post('<?php echo $linkDelete?>', {id : id}, function(){
						table.draw(false);
					})
				}
			})
			return false;
		});	
		
		$('#tbl-data').on('click', '#tbl-status-btn', function () {
			var id = $(this).parents('tr').attr('id');
			var status = $(this).attr('data-status');
			$.post('<?php echo $linkStatus?>', {id : id, status : status}, function(){
				table.draw(false);
			})
			return false;
		});			
		
	}); 
	
</script>